﻿@model ContosoUniversity.Models.Instructor

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Instructor</legend>

        @Html.HiddenFor(model => model.InstructorID)

        <div class="editor-label">
            @Html.LabelFor(model => model.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.FirstMidName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstMidName)
            @Html.ValidationMessageFor(model => model.FirstMidName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.HireDate)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.HireDate)
            @Html.ValidationMessageFor(model => model.HireDate)
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.OfficeAssignment.Location, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.OfficeAssignment.Location)
                @Html.ValidationMessageFor(model => model.OfficeAssignment.Location)
            </div>
        </div>
        <div class="editor-field">
            @{
    System.Text.StringBuilder sb = new System.Text.StringBuilder("<table style='width:100%'><tr>");
    List<ContosoUniversity.Models.Course> list = ViewBag.SelectCourse as List<ContosoUniversity.Models.Course>;
    for (int i = 0; i < list.Count; i++)
    {
        if (i != 0 && i % 3 == 0)
        {
            sb.Append("</tr><tr>");
        }

        string IsSelect = string.Empty;
        if (Model.Courses.Contains(list[i]))
        {
            IsSelect = "checked='checked'";
        }
        sb.Append("<td><input type='checkbox' value='" + list[i].CourseID + "'  " + IsSelect + "    name='selectedCourses'/>" + list[i].Title + "</td>");
    }
    sb.Append("</tr></table> ");
            }
            @MvcHtmlString.Create(sb.ToString())
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
